SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[paAceptarTramite]

@IdTramite INT

AS
SET NOCOUNT ON
DECLARE @Error INT
SET @Error = 0
DECLARE @Usuario INT

BEGIN TRANSACTION

-- Obtengo el usuario registrado
SELECT @Usuario = IdUsuario FROM tb_Usuarios WHERE NTUser = SYSTEM_USER

UPDATE tb_Tracking SET Responsable = @Usuario, FechaRecepcion = GETDATE(), 
Estado = 4 WHERE Tramite = @IdTramite AND Estado = 2
SELECT @Error = @@ERROR

IF @Error <> 0 GOTO Salir

Salir:

IF @Error = 0
	COMMIT TRANSACTION
ELSE
	ROLLBACK TRANSACTION
GO
GRANT EXECUTE ON  [dbo].[paAceptarTramite] TO [GestionDeDocumentos]
GO
